/**
 * @file     isIsomorphic.ts
 * @brief    [205. 同构字符串](https://leetcode.cn/problems/isomorphic-strings/description/)
 * @author   Zhu
 * @date     2022-11-05 12:47
 */

// 双射
function isIsomorphic(s: string, t: string): boolean {
    if (s.length !== t.length) return false;

    const mapS = {};
    const mapT = {};
    for (let i = 0; i < s.length; i++) {
        if (!mapS[s[i]]) {
            if (!mapT[t[i]]) {
                mapS[s[i]] = t[i];
                mapT[t[i]] = s[i];
            } else {
                return false;
            }
        } else if (mapS[s[i]] !== t[i]) {
            return false;
        }
    }

    return true;
}
